﻿using System.Collections.Generic;

namespace _1_7
{
    class Product
    {
        readonly string name;
        public string Name { get { return name; } }

        readonly decimal price;
        public decimal Price { get { return price; } }

        public Product(string name, decimal price)
        {
            this.name = name;
            this.price = price;
        }

        public static List<Product> GetSampleProducts()
        {
            return new List<Product>
            {
                new Product(name: "West Side Story", price: 9.99m),
                new Product(name: "Assassins", price: 14.99m),
                new Product(name: "Frogs", price: 13.99m),
                new Product(name: "Sweeny", price: 10.99m)
            };
        }

        public override string ToString()
        {
            return string.Format("{0}: {1}", name, price);
        }
    }

    class Program
    {
        static void Main_()
        {
            List<Product> products = Product.GetSampleProducts();
            products.Sort(delegate (Product x, Product y)
            { return x.Name.CompareTo(y.Name); });
            foreach (Product product in products)
            {
                System.Console.WriteLine(product);
            }
        }
    }
}
//直接使用委托进行比较，而不是创建一个新类型